package test;

import java.util.Scanner;

public class Question2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextLong();
        }
        long[] prefix = new long[n+1];
        for (int i = 1; i <= n; i++) {
            prefix[i] = prefix[i -1] + a[i -1];
        }

        long ans = 0;
        for (int i = 0; i <= n; i++) {
            ans = Math.max(ans, Math.abs(prefix[i]));
        }
        long[] maxSu = new long[n];
        long[] minSu = new long[n];
        if(n > 0){
            maxSu[n-1] = prefix[n];
            minSu[n -1] = prefix[n];
        }
        for (int i = n -2; i >= 0 ; i--) {
            maxSu[i] = Math.max(prefix[i+1],maxSu[i+1] );
            minSu[i] = Math.min(prefix[i+1],minSu[i+1] );
        }
        for (int k = 0; k < n; k++) {
            long candidate1 = Math.abs(maxSu[k] - 2*prefix[k]);
            long candidate2 = Math.abs(minSu[k] - 2*prefix[k]);
            ans = Math.max(ans, Math.max(candidate1, candidate2));
        }
        System.out.println(ans);
    }
}
